package j2;
import java.io.*;
import java.util.regex.Pattern;

public class text {
    private static String[] e = new String[1000];
    private static int i=0;
    public static void main(String[] args) {
        Pattern pattern = Pattern.compile("^\\s*\\d{1,3}\\s*[-+]\\s*\\d{1,3}\\s*=\\s*-?\\d{1,3}\\s*$");
        try (BufferedReader reader = new BufferedReader(new FileReader("src/main/java/j2/errortext.txt"))) {
            String l;
            while ((l = reader.readLine()) != null && i < e.length) {
                if (pattern.matcher(l).matches()) {
                        e[i] = l;
                        i++;
                }
            }
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }
        try (BufferedWriter writer = new BufferedWriter(new FileWriter("src/main/java/j2/data.txt", false))) {

            for (int j = 0; j < i; j++) {
                if (e[j] != null) {
                    writer.write(e[j]);
                    writer.newLine();
                }
            }
        } catch (IOException ex) {
            System.out.println("保存错误答案时出错: " + ex.getMessage());
        }
    }
}